//
//  SLBaseNavigationViewController.m
//  StarLight
//
//  Created by apple on 16/8/19.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLBaseNavigationViewController.h"

@interface SLBaseNavigationViewController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate>

@property (assign, nonatomic) BOOL isSwitching;

@end

@implementation SLBaseNavigationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

// 重载 push 方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (animated) {
        if (self.isSwitching) {
            return; // 1. 如果是动画，并且正在切换，直接忽略
        }
        self.isSwitching = YES; // 2. 否则修改状态
    }
    if (self.childViewControllers.count > 0) {
        // 隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;
    }
// 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
// 意思是，我们任然可以重新在push控制器的viewDidLoad方法中设置导航栏的leftBarButtonItem，如果设置了就会覆盖在push方法中设置的“返回”按钮，因为 [super push....]会加载push的控制器执行viewDidLoad方法。
    [super pushViewController:viewController animated:animated];
}


#pragma mark - UINavigationController

//- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
//    if (!self.isSwitching) {
//        return [super popToViewController:viewController animated:animated];
//    } else {
//        [self enqueuePopViewController:viewController animate:animated];
//        return nil;
//    }
//}
//
//- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
//    if (!self.isSwitching) {
//        return [super popViewControllerAnimated:animated];
//    } else {
//        [self enqueuePopViewController:nil animate:animated];
//        return nil;
//    }
//}
//
//#pragma mark - UINavigationControllerDelegate
//
//- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
//    self.isSwitching = NO;
//    
//    self.interactivePopGestureRecognizer.enabled = YES;
//    
//    // 显示完毕之后判断是否需要Pop
//    if (self.popVCAnimateQueue.count) {
//        PopVCInfo *info = [self.popVCAnimateQueue firstObject];
//        [self.popVCAnimateQueue removeObjectAtIndex:0];
//        if (info.controller) {
//            [self.navigationController popToViewController:info.controller animated:info.animate];
//        } else {
//            [self.navigationController popViewControllerAnimated:info.animate];
//        }
//    }
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
